/**
 * Created by zhu on 2015/12/28.
 */
$(function(){

    //$('#hotGoods')
    $.get(contextPath + "/index/best", function (data) {
        loadBest(data);
    });

    $.get(contextPath + "/index/hot", function (data) {

        loadHot(data);
    });

    $.get(contextPath + "/index/wheel", function (data) {

        loadWheel(data);
    });


});

function loadWheel(data){
    var slider = $('#slider');
    slider.empty();
    data = $.parseJSON(data);
    $.each(data.list,function(i,item){
        var temp;
        temp = ' <li> <img src="'+contextPath+item.goods.index_url+'" alt="" onclick="productDetails('+item.goods.id+')"> </li>';
        slider.append(temp)
    });
    slider.responsiveSlides({
        auto: true,
        pager: false,
        nav: true,
        speed: 500,
        // 对应外层div的class : slide_container
        namespace: "slide"
    });
}

function loadHot(data){
   data = $.parseJSON(data);
   if(data.status == 1){
       alert("请求失败");
   }else{

       var hotGoodsDiv = $('#hotGoods');
       hotGoodsDiv.empty();
       var tempDiv;
       $.each(data.list,function(i,item){
           var mydiv;

          if(i%2 == 0){
              tempDiv = document.createElement("div");
              $(tempDiv).addClass("row hotGoods");
              mydiv = ' <div class="col-50"> ';
              mydiv += '<div class = "hot_goods">';
              mydiv += '<a onclick="productDetails('+item.goods.id+')">';
              mydiv += '  <img src="'+contextPath+item.goods.index_url+'" > ';
              mydiv += ' <div class="goodsTitle">'+item.goods.name+'</div>  ';
              mydiv += '  <div class="description"><i class="fa fa-jpy">'+item.goods.price+'</i></div></a></div></div> ';

          }else{
              mydiv = ' <div class="col-50"> ';
              mydiv += '<div class = "hot_goods">';
              mydiv += '<a onclick="productDetails('+item.goods.id+')">';
              mydiv += '  <img src="'+contextPath+item.goods.index_url+'" > ';
              mydiv += ' <div class="goodsTitle">'+item.goods.name+'</div>  ';
              mydiv += '  <div class="description"><i class="fa fa-jpy">'+item.goods.price+'</i></div></a> ';
              mydiv += '  </div> ';
              mydiv += '  </div> ';

          }
           $(tempDiv).append(mydiv);
           hotGoodsDiv.append(tempDiv);
       });


   }

}

function loadBest(data){
    data = $.parseJSON(data);
    if(data.status == 1){
        alert("请求失败");
    }else{
        var hotGoodsDiv = $('#bestGoods');
        var tempDiv;
        $.each(data.list,function(i,item){
            if(i == 0){
                tempDiv = '<div class="row"><div class="col-50 margin-left">';
                tempDiv +='<a onclick="productDetails('+item.goods.id+')">';
                tempDiv += '<img src="'+contextPath+item.goods.index_url+'" style="height: 330px"></a></div>';
            }else if (i == 1){
                tempDiv += '<div class="col-50 fix-img">';
                tempDiv +='<a onclick="productDetails('+item.goods.id+')">';
                tempDiv += '<div class="fix-img1">';
                tempDiv += '<img src="'+contextPath+item.goods.index_url+'"></div></a></div>'

            }else if(i == 2){
                tempDiv += '<div class="col-50 fix-img">';
                tempDiv +='<a onclick="productDetails('+item.goods.id+')">';
                tempDiv += '<div style="margin-top: 20px;" class="fix-img1">';
                tempDiv += '<img src="'+contextPath+item.goods.index_url+'"></div></a></div></div>'
            }
        });
        hotGoodsDiv.append(tempDiv);
    }
}
